﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Bunbyx.game
{
    public class PauseScreen : Screen
    {
        // --------------------------------------------------------------------
        //  Constants
        // --------------------------------------------------------------------

        private const string SCREEN_NAME = "Screens/pause";

        private Vector2 POSITION = new Vector2(370, 200);

        // --------------------------------------------------------------------
        //  Delegates
        // --------------------------------------------------------------------

        public delegate void PauseGame();
        public delegate void RestartLevel();
        public delegate void MainMenu();

        // --------------------------------------------------------------------
        //  Attributes
        // --------------------------------------------------------------------

        private Camera camera;
        private Texture2D bgTexture;
        private PauseGame pauseGameHandler;
        private RestartLevel restartLevelHandler;
        private MainMenu mainMenuHandler;
        private SpriteFont font;

        // --------------------------------------------------------------------
        //  Constructor
        // --------------------------------------------------------------------

        public PauseScreen(Camera camera, PauseGame pauseGameHandler, RestartLevel restartLevelHandler, MainMenu mainMenuHandler)
        {
            this.camera = camera;
            this.pauseGameHandler = pauseGameHandler;
            this.restartLevelHandler = restartLevelHandler;
            this.mainMenuHandler = mainMenuHandler;
        }

        // --------------------------------------------------------------------
        //  Public methods
        // --------------------------------------------------------------------

        public override void LoadContent(ContentManager content)
        {
            bgTexture = content.Load<Texture2D>(SCREEN_NAME);
            font = content.Load<SpriteFont>(Hud.FONT_NAME);
        }

        public override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                pauseGameHandler();
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Tab))
            {
                pauseGameHandler();
                restartLevelHandler();
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Back))
            {
                pauseGameHandler();
                mainMenuHandler();
            }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(bgTexture, camera.Position + POSITION, Color.White);
            spriteBatch.DrawString(font, "         [Enter] to continue", new Vector2(250, 450), Color.Black);
            spriteBatch.DrawString(font, "        [Tab] to restart level", new Vector2(250, 500), Color.Black);
            spriteBatch.DrawString(font, "[Backspace] to return to main menu", new Vector2(250, 550), Color.Black);
        }
    }
}
